package com.task.manage.system.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.task.manage.common.annotation.Log;
import com.task.manage.common.enums.BusinessType;
import com.task.manage.system.domain.MerchantTaskPriority;
import com.task.manage.system.service.IMerchantTaskPriorityService;
import com.task.manage.common.core.controller.BaseController;
import com.task.manage.common.core.domain.AjaxResult;
import com.task.manage.common.utils.poi.ExcelUtil;
import com.task.manage.common.core.page.TableDataInfo;

/**
 * 商家任务优先级Controller
 *
 * @author ruoyi
 * @date 2024-05-15
 */
@Controller
@RequestMapping("/system/priority")
public class MerchantTaskPriorityController extends BaseController {
    private String prefix = "system/priority";

    @Autowired
    private IMerchantTaskPriorityService merchantTaskPriorityService;

    @RequiresPermissions("system:priority:view")
    @GetMapping()
    public String priority() {
        return prefix + "/priority";
    }

    /**
     * 查询商家任务优先级列表
     */
    @RequiresPermissions("system:priority:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerchantTaskPriority merchantTaskPriority) {
        startPage();
        List<MerchantTaskPriority> list = merchantTaskPriorityService.selectMerchantTaskPriorityList(merchantTaskPriority);
        return getDataTable(list);
    }

    /**
     * 导出商家任务优先级列表
     */
    @RequiresPermissions("system:priority:export")
    @Log(title = "商家任务优先级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantTaskPriority merchantTaskPriority) {
        List<MerchantTaskPriority> list = merchantTaskPriorityService.selectMerchantTaskPriorityList(merchantTaskPriority);
        ExcelUtil<MerchantTaskPriority> util = new ExcelUtil<MerchantTaskPriority>(MerchantTaskPriority.class);
        return util.exportExcel(list, "商家任务优先级数据");
    }

    /**
     * 新增商家任务优先级
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商家任务优先级
     */
    @RequiresPermissions("system:priority:add")
    @Log(title = "商家任务优先级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerchantTaskPriority merchantTaskPriority) {
        return toAjax(merchantTaskPriorityService.insertMerchantTaskPriority(merchantTaskPriority));
    }

    /**
     * 修改商家任务优先级
     */
    @RequiresPermissions("system:priority:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MerchantTaskPriority merchantTaskPriority = merchantTaskPriorityService.selectMerchantTaskPriorityById(id);
        mmap.put("merchantTaskPriority", merchantTaskPriority);
        return prefix + "/edit";
    }

    /**
     * 修改保存商家任务优先级
     */
    @RequiresPermissions("system:priority:edit")
    @Log(title = "商家任务优先级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerchantTaskPriority merchantTaskPriority) {
        return toAjax(merchantTaskPriorityService.updateMerchantTaskPriority(merchantTaskPriority));
    }

    /**
     * 删除商家任务优先级
     */
    @RequiresPermissions("system:priority:remove")
    @Log(title = "商家任务优先级", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(merchantTaskPriorityService.deleteMerchantTaskPriorityByIds(ids));
    }
}
